package com.bcu.calculus.service.serviceImpl;

import com.bcu.calculus.entity.Message;
import com.bcu.calculus.entity.Review;
import com.bcu.calculus.utils.SendUtil;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import com.bcu.calculus.entity.Remark;
import com.bcu.calculus.mapper.RemarkMapper;
import com.bcu.calculus.service.RemarkService;

import java.util.Date;
import java.util.List;

@Service
public class RemarkServiceImpl implements RemarkService{

    @Resource
    private RemarkMapper remarkMapper;

    @Override
    public Message<?> add(Remark record) {
        String remarkId = "RM" + SendUtil.genSendId();
        record.setRemarkCreateTime(new Date());
        record.setRemarkUpdateTime(new Date());
        record.setRemarkId(remarkId);
        return remarkMapper.insertSelective(record) > 0 ? Message.success(null) : Message.fail(null);
    }

    @Override
    public Message<?> del(String remarkId) {
        return remarkMapper.deleteByPrimaryKey(remarkId) > 0 ? Message.success(null) : Message.fail(null);
    }

    @Override
    public Message<?> update(Remark record) {
        record.setRemarkUpdateTime(new Date());
        return remarkMapper.updateByPrimaryKeySelective(record) > 0 ? Message.success(null) : Message.fail(null);
    }

    @Override
    public Message<List<Remark>> selectAll() {
        return Message.success(null).add(remarkMapper.selectByAll());
    }

    @Override
    public Message<Remark> selectByPK(String remarkId) {
        return Message.success(null).add(remarkMapper.selectByPrimaryKey(remarkId));
    }

    @Override
    public Message<Remark> selectBySendId(String sendId) {
        return Message.success(null).add(remarkMapper.selectByRemarkSendId(sendId));
    }


}
